package org.gap.wizards.world.actions;

import org.gap.wizards.items.Item;
import org.gap.wizards.items.ItemFactory;
import org.gap.wizards.pc.PlayerCharacter;
import org.gap.wizards.pc.Skill;
import org.gap.wizards.pc.skills.ResultType;
import org.gap.wizards.utils.Dice;
import org.gap.wizards.views.MessageOutput;
import org.gap.wizards.world.Location;
import org.gap.wizards.world.TimerState;
import org.gap.wizards.world.WorldAction;

public class ForagingAction implements WorldAction {

	private PlayerCharacter pc;
	private MessageOutput output;
	private Location map;
	private final TimerState timer;

	public ForagingAction(PlayerCharacter pc, MessageOutput output, Location activeMap, TimerState timer) {
		this.pc = pc;
		this.output = output;
		this.map = activeMap;
		this.timer = timer;
	}
	
	@Override
	public void perform() {
		Skill foraging = pc.getSkill("Foraging");
		if (foraging == null) {
			output.addMessage("You do not have foraging skill");
			return;
		}
		for (int i = 0; i < 10; i++) {
			timer.tick();
		}
		output.addMessage("You begin foraging the area.");
		if (foraging.rollWithModifier(0) == ResultType.SUCCESS) {
			Item found = null;
			switch(Dice.D6.roll()) {
			case 1:
			case 2:
			case 3:
				found = ItemFactory.beesWax();
				break;
			case 4 :
			case 5:
			case 6:
				found = ItemFactory.greenLeaves();
			}
			map.addItem(found);
			output.addMessage("You found " + found + ".");
		} else {
			output.addMessage("You don't find anyting useful.");
		}
	}

}
